package com.han.state.before;

/**
 * @ClassName Lift
 * @Description 电梯类（ILift的子实现类）
 * @Author duoduo Han
 * @Date 2024/6/16 11:51
 */
public class Lift implements ILift {
    // 声明一个记录当前电梯状态的变量
    private int state;

    @Override
    public void setState(int state) {
        this.state = state;
    }

    @Override
    public void open() {
        switch (state) { //当前电梯状态
            case RUNNING_STATE:
            case OPENING_STATE:
                //什么都不做
                break;
            case CLOSING_STATE:
            case STOPPING_STATE:
                System.out.println("电梯打开了...");
                setState(OPENING_STATE);
                break;
        }
    }

    @Override
    public void close() {
        switch (state) {
            case STOPPING_STATE:
            case OPENING_STATE:
                System.out.println("电梯关闭了...");
                setState(CLOSING_STATE);
                break;
            case RUNNING_STATE:
            case CLOSING_STATE:
                //什么都不做
                break;
        }
    }

    @Override
    public void run() {
        switch (state) {
            case STOPPING_STATE:
            case CLOSING_STATE:
                System.out.println("电梯正在运行...");
                setState(RUNNING_STATE);
                break;
            case OPENING_STATE:
            case RUNNING_STATE:
                //什么都不做
                break;
        }

    }

    @Override
    public void stop() {
        switch (state) {
            case STOPPING_STATE:
            case OPENING_STATE:
                //什么都不做
                break;
            case CLOSING_STATE:
            case RUNNING_STATE:
                System.out.println("电梯停止了...");
                setState(STOPPING_STATE);
                break;
        }

    }
}
